<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">

    <title>Document</title>
    <style>
        .demo {
            width: 80px;
            background: pink;
            position: absolute;
            left: 0;
            top: 100px;
        }
    </style>
</head>

<body>


    <div class="demo">deno</div>
    <button id="stop">stop</button>
    <script>
        var oDemo = document.getElementsByClassName('demo')[0],
            oStop = document.getElementById('stop');
        var req;

        function move() {
            console.log('99999')
            var l = oDemo.offsetLeft;
            if (l < 1000) {
                oDemo.style.left = l + 2 + 'px';
                req = requestAnimationFrame(move); //当页面刷新时执行下一次
            } else {
                oDemo.style.left = '1000px';
            }

        }
        move();
        oStop.onclick = function () {
            cancelAnimationFrame(req);
        } //点击时清除req
        

        // requestAnimationFrame 动画更加的平滑
    </script>





</body>

</html>